/**
 * @(#) ReqVacationMediator.as
 *
 * @date		2009. 03. 06.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	복리후생 - 선택적복리후생 신청 - Mediator
 * 				선택적 복리후생 신청 Presentation Logic을 관리 
 */
package com.skt.common_hr.welfare.view
{
	import com.skt.common_hr.welfare.WelfareFacade;
	import com.skt.common_hr.welfare.model.WelfareCodesProxy;
	import com.skt.common_hr.welfare.model.WelfareDetailProxy;
	import com.skt.common_hr.welfare.view.components.ReqWelfareView;
	
	import flash.events.Event;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	
	public class ReqWelfareViewMediator extends Mediator
	{
		public static const NAME:String = "ReqWelfareViewMediator"; 

		public var Gkey:String;	

		/**
		* 생성자
		* 
		* @param
		* @return void
		*/
        public function ReqWelfareViewMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
            view.callLater(initView);
            
        }
 		
		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		*/
 		public function initView():void
 		{
 			// 각 버튼들의 Event Handler를 설정하고
 			view.addEventListener(ReqWelfareView.CANCEL_WELFARE, onCancel);
 			view.addEventListener(ReqWelfareView.MODIFY_WELFARE, onModify);
 			//view.addEventListener(ReqWorkTimeView.DEL_RECORD, onDelRecord);
 			onSelectedWelFareDetail();
 			setCodeList();
 		}
 		
 		private function setCodeList():void
 		{
 			var proxy:WelfareCodesProxy = facade.retrieveProxy(WelfareCodesProxy.NAME) as WelfareCodesProxy;
 			view.usedClassList = proxy.usedClassList;
 			view.usedItemList = proxy.usedItemList;
 		}
 		
 		private function onModify(event:Event):void{
 			facade.sendNotification(WelfareFacade.QUICK_MODIFY_VIEW, this);
 		}
 		
 		/**
 		 * 키값에 대한 공통데이터 조회
 		 * **/
 		private function onSelectedWelFareDetail():void
 		{
 			trace("Gkey :  " + Gkey);
 			var proxy:WelfareDetailProxy = facade.retrieveProxy(WelfareDetailProxy.NAME) as WelfareDetailProxy;
 			proxy.load(Gkey);
 		}
		
 		
 		private function clearView():void
 		{
 			trace("clear Work");
 		}
 		
 		private function onCancel(event:Event):void
 		{
 			facade.sendNotification(WelfareFacade.CANCEL_WELFARE_VIEW, this);
 			trace("onCancel suss");
 		}
 		
 		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		* 
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array 
		{
			return [
					WelfareFacade.LOAD_WELFARE_DETAIL_COMPLETE,
					WelfareFacade.LOAD_WELFARE_DETAIL_FAILED
					];
		}
		

		/**
		* Noti별로 처리한다.
		* 
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
			switch(note.getName()) 
			{
				case WelfareFacade.LOAD_WELFARE_DETAIL_COMPLETE:
					view.welfareDetailList = (note.getBody() as WelfareDetailProxy).detailList
					view.detailMaster = (note.getBody() as WelfareDetailProxy).detailMaster;
					break;
				case WelfareFacade.LOAD_WELFARE_DETAIL_FAILED:
					trace("WelfareFacade.LOAD_WELFARE_DETAIL_FAILED ");
					break;
				default:
					//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
					break;
			}
		}
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Utility Functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
        private function get view():ReqWelfareView
        {
            return viewComponent as ReqWelfareView;
        }
	}
}